package com.android.svmc.app.mobile.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.svmc.app.mobile.activity.R;
import com.android.svmc.app.mobile.model.MenuItem;
import com.android.svmc.app.mobile.view.FontTextView;

public class MenuStoryAdapter extends BaseAdapter {

	Context mcontext;
	private LayoutInflater mInflater;
	ArrayList<MenuItem> listcategory = new ArrayList<MenuItem>();
	public MenuStoryAdapter(Context context,
			ArrayList<MenuItem> categories) {
		mcontext = context;
		listcategory = categories;
		mInflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {

		return listcategory.size();
	}

	@Override
	public Object getItem(int position) {

		return listcategory.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}
	

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public View getView(int position, View view, ViewGroup parentview) {
		ViewHolder holder;
		if (view == null) {
			mInflater = (LayoutInflater) mcontext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = mInflater.inflate(R.layout.item_gridview_mainmenu, null);
			holder = new ViewHolder();
			holder.thumbnail = (ImageView) view
					.findViewById(R.id.item_grview_mainmenu_img_thumnail);
			holder.title = (TextView) view
					.findViewById(R.id.item_grview_mainmenu_txt_title);
			holder.description = (TextView) view
					.findViewById(R.id.item_grview_mainmenu_txt_desciption);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		FontTextView.setfontMyriadPro_semiBold(holder.title, mcontext);
		FontTextView.setfontMyriadPro_regular(holder.description, mcontext);
		holder.title.setText(listcategory.get(position).getTitle());
		holder.description.setText(listcategory.get(position).getDescription());		
		if(listcategory.get(position).getId()==6){
			holder.thumbnail.setImageResource(R.drawable.icon_hatgiongtamhon);
		}else if (listcategory.get(position).getId()==8) {
			holder.thumbnail.setImageResource(R.drawable.icon_tamsu);
		}else if (listcategory.get(position).getId()==4) {
			holder.thumbnail.setImageResource(R.drawable.icon_truyen_cuoi);
		}else if (listcategory.get(position).getId()==5) {
			holder.thumbnail.setImageResource(R.drawable.icon_truyenngan);
		}else if (listcategory.get(position).getId()==7) {
			holder.thumbnail.setImageResource(R.drawable.icon_voz);
		}else {
			holder.thumbnail.setImageResource(R.drawable.icon_default);
		}

		return view;
	}

	static class ViewHolder {
		ImageView thumbnail;
		TextView title;
		TextView description;

	}

}
